package com.woniuxy.factories;

import com.woniuxy.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FourthFactory {
    public Person doPerson(){
        //1.读取配置文件
        Properties properties = new Properties();
        //2.获取一个InputStream
        InputStream resourceAsStream = FourthFactory.class.getResourceAsStream("person.properties");
        //3.读取配置文件
        try {
            properties.load(resourceAsStream);
            //通过key获取全限定类名
            String person = properties.getProperty("person");
            Person person1 = (Person) Class.forName(person).newInstance();
            return person1;
        } catch (IOException e) {
            e.printStackTrace();
        }
        catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
